<template>
    <div id="tmpl">
        <div id="title">
            <h4>{{imginfo.title}}</h4>
            <p>{{imginfo.add_time | datefmt('YY-MM-DD HH:mm:ss')}} {{imginfo.click}}次浏览</p>
            <div class="line"></div>
            <div class="mui-content">
                <ul class="mui-table-view mui-grid-view mui-grid-9">
                    <li class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3" v-for="(item, index) in list">
                        <img class="preview-img"  :src="item.src" height="100" @click="$preview.open(index, list)">
                    </li>
                </ul>
            </div>
            <p v-html="imginfo.content"></p>
        </div>
        <!--评论组件-->
        <comment :id='id'>

        </comment>
    </div>
</template>
<script>
    import comment from '../subcomment/comment.vue'
    import common from '../../kits/common.js';
    import {Toast} from 'mint-ui';

    export default{
        components:{
            comment
        },
        data(){
            return{
                imginfo:{},
                list:[]
            }
        },
        created(){
            this.id = this.$route.params.id;
            this.getinfo();
            this.getinfoimgs();
        },
        methods:{
            getinfo(){
                var url = common.apidomain + '/api/getimageInfo/'+ this.id;
                this.$http.get(url).then(function (res) {
                        var data = res.body;
                        if(data.status!=0){
                            Toast(data.message);
                            return;
                        }
                        this.imginfo = data.message[0];
                })
            },
            getinfoimgs(){
                var url = common.apidomain + '/api/getthumimages/'+ this.id;
                this.$http.get(url).then(function (res) {
                    var data = res.body;
                    if(data.status!=0){
                        Toast(data.message);
                        return;
                    }
                    data.message.forEach(function (item) {
                        var img = document.createElement('img');
                        img.src = item.src;
                        item.h = img.height;
                        item.w = img.width;
                    })
                    this.list = data.message;
                })
            }
        }
    }
</script>
<style scoped>
    #title{
        padding: 10px;
    }
    #title h4{
        color: #0094ff;
    }
    #title p{
        color: rgba(0,0,0,.4);
    }
    #title .line{
        width: 100%;
        height: 3px;
        background-color: #ddd;
    }
    /**/
    .mui-content,.mui-content ul{
        background-color: #fff;
    }
    .mui-grid-view.mui-grid-9 .mui-table-view-cell {
        border:0px;
    }
    .mui-grid-view.mui-grid-9{
        border:0px;
    }
    .mui-content img{
        width: 100px;
        height: 100px;
    }
</style>